package com.ruoyi.whole.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.whole.domain.InfoBulkAddVo;
import com.ruoyi.whole.domain.InfoBulkPlanAddVo;
import com.ruoyi.whole.domain.InfoWholeTarget;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.whole.domain.InfoWholePlan;
import com.ruoyi.whole.service.IInfoWholePlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 目标管理-部门整体任务Controller
 *
 * @author ruoyi
 * @date 2022-02-09
 */
@Api(tags = "目标管理-部门整体任务")
@RestController
@RequestMapping("/whole/plan")
public class InfoWholePlanController extends BaseController {
    @Autowired
    private IInfoWholePlanService infoWholePlanService;

    /**
     * 查询目标管理-部门整体任务列表
     */
    @PreAuthorize("@ss.hasPermi('whole:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoWholePlan infoWholePlan) {
        startPage();
        List<InfoWholePlan> list = infoWholePlanService.selectInfoWholePlanList(infoWholePlan);
        return getDataTable(list);
    }

    /**
     * 导出目标管理-部门整体任务列表
     */
    @PreAuthorize("@ss.hasPermi('whole:plan:export')")
    @Log(title = "目标管理-部门整体任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoWholePlan infoWholePlan) {
        List<InfoWholePlan> list = infoWholePlanService.selectInfoWholePlanList(infoWholePlan);
        ExcelUtil<InfoWholePlan> util = new ExcelUtil<InfoWholePlan>(InfoWholePlan.class);
        util.exportExcel(response, list, "目标管理-部门整体任务数据");
    }

    /**
     * 获取目标管理-部门整体任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('whole:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(infoWholePlanService.selectInfoWholePlanById(id));
    }

    /**
     * 新增目标管理-部门整体任务
     */
    @PreAuthorize("@ss.hasPermi('whole:plan:add')")
    @Log(title = "目标管理-部门整体任务", businessType = BusinessType.INSERT)
    @ApiOperation("新增目标管理-部门整体任务")
    @ApiImplicitParam(name = "infoWholePlan", value = "实体类", dataType = "InfoWholePlan")
    @PostMapping
    public AjaxResult add(@RequestBody InfoWholePlan infoWholePlan) {
        return toAjax(infoWholePlanService.insertInfoWholePlan(infoWholePlan));
    }

    /**
     * 修改目标管理-部门整体任务
     */
    @PreAuthorize("@ss.hasPermi('whole:plan:edit')")
    @Log(title = "目标管理-部门整体任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoWholePlan infoWholePlan) {
        return toAjax(infoWholePlanService.updateInfoWholePlan(infoWholePlan));
    }

    /**
     * 删除目标管理-部门整体任务
     */
    @PreAuthorize("@ss.hasPermi('whole:plan:remove')")
    @Log(title = "目标管理-部门整体任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoWholePlanService.deleteInfoWholePlanByIds(ids));
    }

    /**
     * 批量新增
     */
    @RequestMapping(value = "/addBulkPlan", method = RequestMethod.POST)
    @ApiOperation("批量新增")
    @ApiImplicitParam(name = "infoBulkPlanAddVo", value = "实体类", dataType = "InfoBulkPlanAddVo")
    public AjaxResult addBulkPlan(@RequestBody InfoBulkPlanAddVo infoBulkPlanAddVo) {
        return toAjax(infoWholePlanService.batchInsert(infoBulkPlanAddVo));
    }
}
